﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebSchedulerDemo.PlanDataSetTableAdapters;

namespace WebSchedulerDemo.db {
	public partial class Project : System.Web.UI.Page {
		PlanDataSet.ProjectsRow row;

		protected void Page_Load(object sender, EventArgs e) {
			Response.Cache.SetCacheability(HttpCacheability.NoCache);

			int id = int.Parse(Request["id"]);
			using (ProjectsTableAdapter adapter = new ProjectsTableAdapter())
				row = adapter.GetDataByID(id)[0];

			IDLabel.Text = id.ToString();
			if (!IsPostBack) {
				NameText.Text = row.Name;
				DescriptionText.Text = row.Description;
				if (row.IsColorNull())
					ColorDropList.SelectedIndex = 0;
				else
					ColorDropList.SelectedValue = row.Color;
			}
		}

		protected void SaveButton_Click(object sender, EventArgs e) {
			row.Name = NameText.Text;
			row.Description = DescriptionText.Text;
			if (ColorDropList.SelectedIndex==0)
				row.SetColorNull();
			else
				row.Color = ColorDropList.SelectedValue;

			using (ProjectsTableAdapter adapter = new ProjectsTableAdapter())
				adapter.Update(row);

			Response.Redirect("default.aspx");
		}
	}
}
